import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description:stack 栈
 * User: lv
 * Date: 2023-03-12
 * Time: 20:03
 */
public class MyStack {

    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[5];
        this.usedSize = usedSize;
    }

    public void push(int val){
        if(isfull()){
            //扩容
            this.elem=Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize]=val;
        this.usedSize++;
    }

    public boolean isfull(){
        if(this.usedSize==this.elem.length){
            return true;
        }
        return false;
    }

    public int pop(){
        if(isEmpty()){
            throw new RuntimeException("栈为空");
        }
        int oldVal=this.elem[usedSize-1];
        this.usedSize--;
        return oldVal;
    }

    public int peek(){
        if(isEmpty()){
            throw new RuntimeException("栈为空");
        }
        return this.elem[usedSize-1];
    }

    public boolean isEmpty(){
        return usedSize==0;
    }

}
